class_name BaseEnemy
extends CharacterBody2D

enum TOWARD{
	UP = 0,
	DOWN = -1,
}

@export var toward := TOWARD.UP:
	set(v):
		toward = v
		if not is_node_ready():
			await ready
		base_enemy.rotation = toward * PI
@export var item: PackedScene

@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var hurtbox: Hurtbox = $EnemySprite/Hurtbox
@onready var base_enemy: BaseEnemy = $"."
@onready var state_machine: StateMachine = $StateMachine
@onready var stats: Stats = $EnemyStats

func _ready() -> void:
	add_to_group("enemies")

func move(direction: Vector2, running_speed: float) -> void:
	velocity = direction * running_speed
	
	move_and_slide()

func create_fall_item() -> void:
	Game.instance_node(item, global_position, Game.items, global_rotation)

func die() -> void:
	queue_free()

func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
	queue_free()
